package cn.iocoder.yudao.framework.message;

import cn.hutool.core.bean.BeanUtil;

import java.util.Map;

/**
 * 客户端请求消息公共类
 *
 * @author: wds_prc
 * @since: 2024/7/9 22:25
 */
public class ClientRequest extends BaseWebSocketMessage {

    public <T> T readBody(Class<T> clazz) {
        T t = null;
        if (this.getData() != null) {
            try {
                t = clazz.newInstance();
            } catch (InstantiationException e) {
                throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
            BeanUtil.fillBeanWithMap((Map<?, ?>) getData(), t, true);
        }
        return t;
    }


}
